package com.utils;

import java.util.Scanner;

public class ScannerUtils {

	private static Scanner scanner = new Scanner(System.in);

	public static int readFromKeyboard(int cardLength) {
		int cardNumber = 0;

		while (true) {
			String input = scanner.nextLine();
			try {
				cardNumber = Integer.parseInt(input);
				if (cardNumber <= cardLength && cardNumber > 0) {
					cardNumber--;
					break;
				} else {
					System.out.println("You have got " + cardLength
							+ " cards. The card number you have "
							+ "selected is bigger than that.");
				}
			} catch (Exception e) {
				System.out.println("You can only enter integers.");
			}
		}

		return cardNumber;
	}

}
